﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Freeze : MonoBehaviour {

    GameObject enterObj = null;

	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		
        if (null != enterObj)
        {
            float dis = Vector3.Distance(enterObj.transform.position, transform.position);

            if (dis > 0.1)
            {
                Vector3 vDir = transform.position - enterObj.transform.position;

                enterObj.GetComponent<Rigidbody>().velocity = vDir;
            }
            else
            {
                enterObj.GetComponent<Rigidbody>().transform.position = transform.position;
            }
        }

	}

    void OnTriggerEnter(Collider collider)
    {
        if (collider.CompareTag("Player"))
        {
            if (null == enterObj)
            {
                enterObj = collider.gameObject;
            }
        }
    }
}
